package StudyCode.summary.mycollection;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CompareTwoDoubleArraysAndReturnTrueIfBothNotNullAndAreOfEqualLengthAndContainEqualValues {
	public static void main(String[] argv) {
		double[] a1 = new double[]{34.45, 35.45, 36.67, 37.78, 37.0000,
				37.1234, 67.2344, 68.34534, 69.87700};
		double[] a2 = new double[]{34.45, 35.45, 36.67, 37.78, 37.0000,
				37.1234, 67.2344, 68.34534, 69.87700};
		System.out.println("两个数组是否相等？" + arraysAreEqual(a1, a2));
	}

	static public boolean arraysAreEqual(double[] a1, double[] a2) {
		boolean result = true;
		if (a1 == null || a2 == null || a1.length != a2.length) {
			result = false;
		} else {
			for (int i = 0; i < a1.length; ++i) {
				if (Math.abs(a1[i] - a2[i]) > 0.000001) {
					result = false;
					break;
				}
			}
		}
		return result;
	}
}
